<?php


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

class wirebank extends JObject {         
	var $ipn_data = array();         
	var $config;  
   	function __construct($config) { 
   		if (!isset($config->wirebank_information))   	  
   		{
			$config->wirebank_information = '';
			
   		}
   		
   	  $config->param_list = '{Username},{Customer ID},{Customer Name},{Transaction ID},{Amount},{Product Name},{Product ID},{Product type},{Currency},{Site name},{Site URL}';
   	  $this->config = $config;
      $this->config->server = JURI::root().'index.php?option=com_jajobboard&view=japayment&task=payment_return&payment_method=wirebank';
   	}
      	
	function config_form(){
		global $mainframe, $option;
		 $editor =& JFactory::getEditor();
		/* Fill in the config tag below. Note that need not write the form */
		?>	
	<tr>
		<td class="key"><?php echo JText::_('Param list'); ?></td>
		<td>
			<textarea readonly='readonly' rows="2" cols="100"><?php echo $this->config->param_list; ?></textarea>			
		</td>
	</tr>		    
	<tr>
      <td class="key"><?php echo JText::_('Wirebank information');?></td>
      <td>
      <?php echo $editor->display( 'wirebank[wirebank_information]',  htmlspecialchars($this->config->wirebank_information, ENT_QUOTES), '100%', '500', '100%', '100%', array('pagebreak', 'readmore') ) ; ?>
    </tr>

    
	<input name="name" value="wirebank" type="hidden">	  		
		<?php
		
	}
	
	function more_info(){
		
	}		
   
	/**
	* Process notification post from paypal
	*
	*/
	function check_payment(){
		return;
	}
	
	function payment_return() {
		?>
		<div id="Mod18" class="jamod module" style="width: 100%">
		<div>
		<div>
			<div>
			
				<div class="jamod-content" style="overflow: hidden; width: 100%">
					<table width="100%" style="width: 100%">
						<tr>
							<td width="100%">
								<?php echo $this->replace_param($this->config->wirebank_information); ?>
							</td>
						</tr>
						
						
					</table>
				</div>
			</div>
		</div>
		</div>
		</div>
		
		<?php	
		return 'wirebank';	
	}
	
	function payment_cancel() {
		JError::raiseNotice(1,JText::_("You hvae cancelled the wire bank payment or the payment was not completed."));
		JError::raiseNotice(1,JText::_("Please feel free to contact us if your experience was not as it should be."));
	}
	
	function assign_params($vars,$values,$payment)
	{
		
		$vars['pay_to_email'] = $payment->config->pay_to_email;
		$vars['transaction_id'] = $values['item_number'];
		$vars['amount'] = $values['amount'];
		$vars['status_url'] = $payment->config->status_url;
		$vars['return_url'] = $payment->config->return_url;
		$vars['cancel_url'] = $payment->config->cancel_url;
		$vars['currency'] = $payment->config->currency;
		return $vars;
		
	}
	
	function replace_param($content)
	{
		global $jbconfig;
		//Prepare data - Begin - 
		$user = JFactory::getUser();
		$transaction_id = JRequest::getVar('transaction_id');
		$transaction = getItemByFieldName('ja_transactions','id',$transaction_id);
		$transaction = $transaction[0];
		switch ($transaction->product_type)
		{
			case 'P':
				$table_name = 'ja_posting_plans';
				switch ($transaction->value_type)
				{
					case 'standard':
						$transaction->product_type = JText::_('Standard Posting plan');
						break;
					case 'premium':
						$transaction->product_type = JText::_('Premium Posting plan');
						break;
					case 'resume':
						$transaction->product_type = JText::_('Search Resume');
						break;
				}
				break;
			case 'C':
				$table_name = 'ja_posting_plans';
				$transaction->product_type = JText::_('Credits');
				break;
			case 'S':
		}
		$product = getItemByFieldName($table_name,'id',$transaction->product_id);
		$product = $product[0];
		
		//Prepare data - End -
		$param_list = explode(',',$this->config->param_list);
		$arr_map = array();
		for ($i=0;$i<count($param_list);$i++)
		{
			switch ($param_list[$i])
			{
				case '{Username}':
					$arr_map[$param_list[$i]] = $user->username;
					break;
				case '{Customer ID}':
					$arr_map[$param_list[$i]] = $user->id;
					break;
				case '{Customer Name}':
					$arr_map[$param_list[$i]] = $user->name;
					break;
				case '{Transaction ID}':
					$arr_map[$param_list[$i]] = $transaction->id;
					break;
				case '{Amount}':
					$arr_map[$param_list[$i]] = $transaction->amount;
					break;
				case '{Product Name}':
					$arr_map[$param_list[$i]] = $product->title;
					break;
				case '{Product ID}':
					$arr_map[$param_list[$i]] = $product->id;
					break;
				case '{Product type}':
					$arr_map[$param_list[$i]] = $transaction->product_type;
					break;
				case '{Currency}':
					$arr_map[$param_list[$i]] = $transaction->currency_code;
					break;
				case '{Site name}':
					$arr_map[$param_list[$i]] = $jbconfig['emails']->get('sitename');
					break;
				case '{Site URL}':
					$arr_map[$param_list[$i]] = JURI::root();
					break;
			}
		}
		foreach ($arr_map as $key=>$value)
		{
			
			$content = str_ireplace($key,$value,$content);
		}
		return $content;
	}
	function replace_image_link($content)
	{
		$content = str_ireplace('{Site URL}/',JURI::root(),$content);
		return $content;
	}
	
}
?>